package com.jl.gettingstarted

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.*
import org.jetbrains.compose.ui.tooling.preview.Preview
import kotlin.time.Clock
import kotlin.time.ExperimentalTime

@Composable
@Preview
fun App() {
    MaterialTheme {
        var location by remember {mutableStateOf("Europe/Paris")}
        var timeAtLocation by remember {mutableStateOf("No location selected")}
        Column {
            Text(timeAtLocation)
            TextField(
                value = location,
                onValueChange = {
                    location = it
                }
            )
            Button(
                onClick = {
                    timeAtLocation = currentTimeAt(location) ?: "Invalid Location"
                }
            ) {
                Text("Show Time At Location")
            }
        }
    }
}

@OptIn(ExperimentalTime::class)
fun currentTimeAt(location: String): String? {
    return Clock.System.now().toString()
}
